package com.yulongtian.weekCompetition.month202302.week04;

import java.util.Arrays;

/**
 * 欢迎来到第 334 场周赛
 * 可
 *
 * @author yulongTian
 * @create 2023-02-26 10:07
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(leftRigthDifference(new int[]{10, 4})));
    }

    public static int[] leftRigthDifference(int[] nums) {
        int len = nums.length;
        int[] ans = new int[len];
        int[] left = new int[len];
        int[] right = new int[len];
        if (len == 0) {
            return ans;
        }
        //left
        for (int i = 1; i < len; i++) {
            left[i] = left[i - 1] + nums[i - 1];
        }
        //right
        for (int i = len - 2; i >= 0; i--) {
            right[i] = right[i + 1] + nums[i + 1];
        }
        for (int i = 0; i < len; i++) {
            ans[i] = Math.abs(left[i] - right[i]);

        }
        return ans;
    }

}
